package com.vf.admin.client.service.impl;

import com.vf.admin.client.dao.AppGameZpJiangpinDao;
import com.vf.admin.client.service.AppGameZpJiangpinService;
import com.vf.admin.miaodong.entity.GameZpJiangpin;
import com.vf.admin.utils.chouJiang.Award;
import com.vf.admin.utils.chouJiang.Test1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
public class AppGameZpJiangpinServiceImpl implements AppGameZpJiangpinService {
    @Autowired
    private AppGameZpJiangpinDao jiangpinDao;


    @Override
    public void save(GameZpJiangpin jiangpin) {
        jiangpinDao.save(jiangpin);
    }

    @Override
    public GameZpJiangpin get(Integer id) {
        return jiangpinDao.get(id);
    }

    @Override
    public List<GameZpJiangpin> findList() {
        return jiangpinDao.findList();
    }

    @Override
    public Integer turntableDraw(Integer dyc) {
        System.out.println(dyc);
        List<Award> awardList = new ArrayList<Award>();

        Integer num = 0;
        List<GameZpJiangpin> list = jiangpinDao.findList();
        for (GameZpJiangpin jiangpin : list) {
            Award award1 = new Award();
            award1.setAwardName(jiangpin.getId());//10%
            if (jiangpin.getLeixing() != 5) {
                if (dyc == 1) {
                    System.out.println("第一次抽奖");
                    System.out.println("概率：" + jiangpin.getOnegailv());
                    num += Integer.valueOf(jiangpin.getOnegailv());
                    award1.setProbabilityNum(num);

                } else if (dyc == 2) {
                    System.out.println("后续抽奖");
                    System.out.println("概率：" + jiangpin.getOnegailv());
                    num += Integer.valueOf(jiangpin.getLatergailv());
                    award1.setProbabilityNum(num);
                }
            } else {
                award1.setProbabilityNum(1000);
            }

            awardList.add(award1);
        }
/*
        ;
*/
        int userSelect =(int)(Math.random() * 1000) + 1;
        Integer id = Test1.duageAwardInteger(userSelect, awardList);
        return id;
    }
}
